package com.mojito.learn.algorithm.interview;

import com.mojito.learn.algorithm.datastructure.TreeNode;
import org.springframework.util.CollectionUtils;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author liufq
 * @since 2022/4/18 下午3:44
 */
public class ZhaoShang {

    public int getMaxValue1(int[] nums, int[] values) {
        int left = 0, right = nums.length - 1;
        int length = nums.length;

        int val = 0;
        for (int i = 0; i < length; i++) {
            int rightValue = values[i];

            if (nums[left] * rightValue > nums[right] * rightValue) {
                val += nums[left] * rightValue;
                left++;
            } else {
                val += nums[right] * rightValue;
                right--;
            }
        }
        return val;
    }

    public int getMaxValue(int[] nums, int[] values) {
        List<Integer> data = Arrays.stream(nums).boxed().collect(Collectors.toList());
        TreeNode root = getTreeNode(0, data);

        List<String> path = new ArrayList<>();
        constructPaths(root, "", path);

        for (int i = 0; i < values.length; i++) {

        }
        return 0;
    }

    private void constructPaths(TreeNode root, String path, List<String> paths) {
        if (root != null) {
            StringBuilder pathBF = new StringBuilder(path);
            pathBF.append(root.val);
            if (root.left == null && root.right == null) {
                paths.add(pathBF.toString());
            } else {
                pathBF.append(",");
                constructPaths(root.left, pathBF.toString(), paths);
                constructPaths(root.right, pathBF.toString(), paths);
            }
        }
    }

    private TreeNode getTreeNode(int val, List<Integer> data) {
        if (CollectionUtils.isEmpty(data)) {
            return new TreeNode(val);
        }
        TreeNode treeNode = new TreeNode(val);
        treeNode.left = getTreeNode(data.get(0), data.subList(1, data.size()));
        treeNode.right = getTreeNode(data.get(data.size() - 1), data.subList(0, data.size() - 1));
        return treeNode;
    }

    public int[] tranArr(int[] arrA, int K) {
        int min = arrA[0], max = arrA[0];
        for (int i = 0; i < arrA.length - 1; i++) {
            if (arrA[i] < arrA[i + 1]) {
                min = arrA[i] + K;
                max = arrA[i + 1] - K;
            }
        }
        return new int[]{min, max};
    }
}
